#include "StdAfx.h"
#include "NewtonShapes.h"

NewtonShape::NewtonShape(void)
{
    m_fMass = 1.0f;
    m_world = NULL;
}

NewtonShape::~NewtonShape(void)
{
}

/** Init the shape */
void NewtonShape::Init()
{

}

/** Set Mass */
void NewtonShape::SetMass( float m )
{
    //assert( m && "Trying to Set Mass to zero!" );
    m_fMass = m;
	// set the body mass and inertia
	NewtonBodySetMassMatrix (m_ribidBodyBox, m_fMass, m_vInertia.X, m_vInertia.Y, m_vInertia.Z );
}
/** Set Inertia */
void NewtonShape::SetInertia( const MVector3f &I )
{
    m_vInertia = I;
    // set the body mass and inertia
	NewtonBodySetMassMatrix (m_ribidBodyBox, m_fMass, m_vInertia.X, m_vInertia.Y, m_vInertia.Z );
}

/** Set the transformation mat */
void NewtonShape::SetTransMatrix( const MMatrix4x4f &m )
{
    m_mTrans = m;
    NewtonBodySetMatrix (m_ribidBodyBox, m_mTrans.pointer() );
}
/** Get the transformation matrix */
MMatrix4x4f NewtonShape::GetTransMatrix()
{
    NewtonBodyGetMatrix(m_ribidBodyBox, m_mTrans.pointer() );
    return m_mTrans;
}

/** Set Angular Velocity */
void NewtonShape::SetAngularVel( const MVector3f &v )
{
    float f[3];
    f[0] = v.X; f[1] = v.Y; f[2] = v.Z;
    NewtonBodySetOmega (m_ribidBodyBox, f );
}







/*---------------------------------------------------------------------
    Newton Box Primitive
-----------------------------------------------------------------------*/
NewPhyBox::NewPhyBox(NewtonWorld* w) 
{
    m_world = w;
}

/** Init the shape */
void NewPhyBox::Init()
{
    NewtonCollision* collision;
    // create the collision shape
	collision = NewtonCreateBox (m_world, Width, Height, Depth, NULL);
	// create the rigid body
	m_ribidBodyBox = NewtonCreateBody (m_world, collision);

	// Get Rid of the collision
	NewtonReleaseCollision (m_world, collision);

    SetMass( 1.0f );                    // some default values
    SetInertia( MVector3f(5,1,5) );
}